<template>
	<view class="msgBox">

		<!-- 1. 分段器 -->
		<view class="slideBtn">
			<u-subsection :list="tabs" :current="current" mode="button" activeColor="#007aff" bgColor="#f2f2f2"
				@change="changeTab" />
		</view>
		<!-- 2. 内容区 -->
		<view class="content">
			<!-- 基础信息 -->
			<basic-msg v-if="current == 0" :loginHealth="loginHealth" />

			<!-- 健康信息 -->
			<health-info v-if="current == 1" :loginHealth="loginHealth">
				<template #btn>
					<view class="commitBtn">
						<!-- <button @click="show=true">删除家庭成员</button> -->
						<button @click="updateMsg()">保存</button>
					</view>
				</template>
			</health-info>

		</view>

	</view>

</template>

<script setup>
	import {

		ref
	} from 'vue';
	import {
		onLoad
	} from "@dcloudio/uni-app"
	import {
		useUserStore
	} from '../../store/user';
	import {
		residentsSearchApi,
		residentsUpdateApi
	} from '../../api/setting';
	import {
		date
	} from '../../uni_modules/uview-plus/libs/function/test';

	const tabs = ref(['基础信息', '健康信息'])
	const current = ref(0)
	// const healthData = ref({})
	const loginHealth = ref({})



	onLoad((options) => {
		if (options.userId) {
			searchMsg(options.userId)
		}
	})

	// 修改居民信息
	async function updateMsg() {
		const res = await residentsUpdateApi({
			
			...loginHealth.value
		})
		if (res.code == 200) {
			// loginHealth.value = res.data
			uni.showToast({
							title: '保存成功',
							icon: 'success',
							duration: 1000
						});
			
				
		}

	}





	// 查看居民信息
	async function searchMsg(uid) {
		const res = await residentsSearchApi({
			_id: uid
		})
		if (res.code == 200) {
			loginHealth.value = res.data
			console.log(222222, loginHealth.value);
		}

	}

	function changeTab(index) {
		current.value = index
	}
</script>

<style lang="scss" scoped>
	.commitBtn {
		height: 160rpx;
		/* border-top: 1px solid #eee; */
		display: flex;
		
		margin-top: 30rpx;
		padding-right:40rpx;

		button {
			width: 100%;
			height: 88rpx;
			background-color: #2984f8;
			font-size: 16px;
			color: #fff;
			line-height: 88rpx;
			text-align: center;

		}
		}

		.slideBtn {
			padding: 0 40rpx;
			background: #fff;
			padding-bottom: 20rpx;
		}

		.msgBox {
			/* background-color: #f0f8ff; */
		}
</style>